import pandas as pd
import numpy as np
import os
import folium
path = '/Users/Weiyang/Downloads'
os.chdir(path)
dataset = pd.DataFrame.from_csv('dataset.csv')
target = ['INSTNM', 'LATITUDE', 'LONGITUDE', 'ADM_RATE', 'CONTROL', 'LOCALE', 'SAT_AVG', 'PCIP11', 'PCIP14', 'TUITIONFEE_IN', 'TUITIONFEE_OUT', 'MEDIAN_HH_INC', 'UNEMP_RATE', 'GRAD_DEBT_MDN', 'COMPL_RPY_1YR_RT', 'COMPL_RPY_3YR_RT']
focus = dataset[target]
focus.shape
focus.head()
new_target = ['MEDIAN_HH_INC', 'UNEMP_RATE', 'GRAD_DEBT_MDN', 'COMPL_RPY_1YR_RT', 'COMPL_RPY_3YR_RT']
for i in new_target:
focus = focus[focus[i] != 'PrivacySuppressed']
focus.shape
for i in new_target:
focus[i] = pd.to_numeric(focus[i])
focus.describe()
focus.isnull().sum()
first_map = focus[np.isfinite(focus['LONGITUDE'])]
folium_map = folium.Map(location=(32.804407, -96.629080),
zoom_start = 8,
tiles='OpenStreetMap')
for idx, row in first_map.iterrows():
green = '#228B22'
orange = '#FFA500'
blue = '#0000FF'
red = '#ff4545'
### Applying manual scaling by 30
radius = row['PCIP11']*30
threshold = row['GRAD_DEBT_MDN']
if threshold > first_map['GRAD_DEBT_MDN'].quantile(0.25) and threshold <= first_map['GRAD_DEBT_MDN'].quantile(0.5):
color = green
elif threshold > first_map['GRAD_DEBT_MDN'].quantile(0.5) and threshold <= first_map['GRAD_DEBT_MDN'].quantile(0.75):
color = orange
elif threshold > first_map['GRAD_DEBT_MDN'].quantile(0.75):
color = red
else:
color = blue
folium.CircleMarker(location = (row['LATITUDE'], row['LONGITUDE']),
radius = radius,
color = color,
fill=True).add_to(folium_map)
folium_map.save('CS_Map.html')
from IPython.core.display import display, HTML
display(HTML('CS_Map copy.html'))
folium_map2 = folium.Map(location=(32.804407, -96.629080),
zoom_start = 8,
tiles='OpenStreetMap')
for idx, row in first_map.iterrows():
green = '#228B22'
orange = '#FFA500'
blue = '#0000FF'
red = '#ff4545'
### Applying manual scaling by 30
radius = row['PCIP14']*30
threshold = row['GRAD_DEBT_MDN']
if threshold > first_map['GRAD_DEBT_MDN'].quantile(0.25) and threshold <= first_map['GRAD_DEBT_MDN'].quantile(0.5):
color = green
elif threshold > first_map['GRAD_DEBT_MDN'].quantile(0.5) and threshold <= first_map['GRAD_DEBT_MDN'].quantile(0.75):
color = orange
elif threshold > first_map['GRAD_DEBT_MDN'].quantile(0.75):
color = red
else:
color = blue
folium.CircleMarker(location = (row['LATITUDE'], row['LONGITUDE']),
radius = radius,
color = color,
fill=True).add_to(folium_map2)
folium_map2.save('Eng_Map.html')
from IPython.core.display import display, HTML
display(HTML('Eng_Map copy.html'))